package com.whccb.apps.office.document.event.receive;

import me.chanjar.weixin.common.util.StringUtils;

import com.actionsoft.bpms.bo.engine.BO;
import com.actionsoft.bpms.bpmn.engine.core.delegate.ProcessExecutionContext;
import com.actionsoft.bpms.bpmn.engine.listener.InterruptListener;
import com.actionsoft.bpms.bpmn.engine.listener.InterruptListenerInterface;
import com.actionsoft.exception.BPMNError;
import com.actionsoft.sdk.local.SDK;
import com.whccb.apps.office.document.ODConstant;

public class DraftTaskValidateEvent extends InterruptListener implements
		InterruptListenerInterface {
	public String getDescription() {
		return "收文流程，拟稿节点，办理前根据“审核菜单”，判断是否允许通过。如果直接会签，则必须要填写会签人和行领导。";
	}

	public String getProvider() {
		return "ActionSoft";
	}

	public String getVersion() {
		return "AWS 6.0";
	}

	@Override
	public boolean execute(ProcessExecutionContext pec) throws Exception {
		if (pec.isChoiceActionMenu(ODConstant.SW_DRAFT_VALIDATE_CHECKMENU)) {
			BO swBo = SDK.getBOAPI().getByProcess("BO_WHBK_OD_RECEIVE",
					pec.getProcessInstance().getId());
			if (swBo != null) {
				if (StringUtils.isEmpty(swBo.getString("PB"))) {
					throw new BPMNError("wsyh-01", "如果选定的是直接启动会签，请填写办公室批办意见");
				}
				if (StringUtils.isEmpty(swBo.getString("DOUSERID"))
						&& StringUtils.isEmpty(swBo.getString("LEADERMANID"))) {
					throw new BPMNError("wsyh-01",
							"如果选定的是直接启动会签，则会签部门和行领导至少需要选择录入一项");
				}
			}
		}
		return true;
	}
}
